package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.SystemMessage;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.SystemMessageMapper;
import cn.wolfcode.trip.base.service.ISystemMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SystemMessageServiceImpl implements ISystemMessageService {
    @Autowired
    private SystemMessageMapper systemMessageMapper;

    @Override
    public void save(SystemMessage entity, Long[] ids) {
        entity.setCreatetime(new Date());
        if(entity.getId()!=null && "".equals(entity.getId())){
            systemMessageMapper.insert(entity);
        }else if(ids != null){
            for (Long id : ids) {
                User user = new User();
                user.setId(id);
                entity.setUser(user);
                systemMessageMapper.insert(entity);
            }
        }

    }

    @Override
    public Integer selectUnRead(Long id) {
        return systemMessageMapper.selectUnRead(id);
    }

    @Override
    public List<SystemMessage> selectLikesByUserId(Long id) {
        List<SystemMessage> systemMessages = systemMessageMapper.selectSystemMessagesByUserId(id);
        return systemMessages;
    }

    @Override
    public void changeState(Long id) {
        systemMessageMapper.changeState(id);
    }
}
